import util from '@ohos.util';

export default function date(time?:number|string) {
  return new DateTime(time)
}

class DateTime {
  private date:Date = null

  constructor(time?:number|string) {
    if (!time) {
      this.date = new Date()
      return
    }

    if (typeof time == 'number') {
      this.date = new Date(time * 1000)
      return
    }

    if (typeof time == 'string') {
      this.date = new Date(time)
      return
    }
  }

  midnight():DateTime {
    this.date = new Date(this.date.getFullYear(), this.date.getMonth(), this.date.getDate(), 0, 0, 0, 0)
    return this
  }

  unix():number {
    return Math.round(this.date.getTime() / 1000)
  }
}